package person.lance.regexandgame.regex;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringReg {
    String reg = "";
    String source = "";

    public StringReg(String source, String reg) {
        this.reg = reg;
        this.source = source;
    }

    /**
     * 关键字匹配
     * @return
     */
    public List<StringResult> keywordMatch(){
        ArrayList<StringResult> stringResults = new ArrayList<StringResult>();
        Matcher matcher = Pattern.compile(reg).matcher(source);
        while(matcher.find()){
            int start = matcher.start();
            int end = matcher.end();
            StringResult stringResult = new StringResult();
            stringResults.add(stringResult);
        }
        return stringResults;
    }

    public String getReg() {
        return reg;
    }

    public void setReg(String reg) {
        this.reg = reg;
    }

    public String getSource() {
        return source;
    }

    public void setSource(String source) {
        this.source = source;
    }
}
